package com.chandon.juc.thread_basic;

import com.chandon.juc.SleepThread;

/**
 * 描述
 *
 * @author Dong
 * @version 1.0
 * @date 2021-04-10 16:58
 */

public class T04A_Suspend_Rusume_Test {

    public static void main(String[] args) {

        Thread provider = new Thread(new provider("provider"));
        Thread consumer = new Thread(new provider("consumer"));
        provider.setName("provider");
        consumer.setName("consumer");


        provider.start();

        SleepThread.sleep(1);
        consumer.start();
        provider.resume();
        consumer.resume();
        SleepThread.sleep(1);
        System.out.println("over");

    }

    static class provider implements Runnable {
        String name;

        public provider(String name) {
            this.name = name;
        }

        @Override
        public void run() {
            System.out.println(name + "---------in");
            Thread.currentThread().suspend();
            System.out.println(name + "---------out");
        }
    }

    static class consumer implements Runnable {
        String name;

        public consumer(String name) {
            this.name = name;
        }

        @Override
        public void run() {
            System.out.println(name + "---------in");
            Thread.currentThread().suspend();
            System.out.println(name + "---------out");
        }
    }

}
